﻿using UnityEngine;
using System.Collections;

public enum EDirection
{
    LEFT,
    RIGHT,
    BOTTOM,
    TOP
}


public class LevelDatabase {
    private static LevelDatabase m_instance;
    public static LevelDatabase Instantiate()
    {
        if (m_instance == null)
            m_instance = new LevelDatabase();
        return m_instance;
    }

    private DataTexture dataTexture;

    public DataTexture DataTexture
    {
        get { return dataTexture; }
        set { dataTexture = value; }
    }
    private TextAsset[] _Waves;

    public TextAsset[] Waves
    {
        get { return _Waves; }
        set { _Waves = value; }
    }

    

    public void ReadDatabase()
    {
        ReadWaves();
        ReadImageAgent();
        ReadOther();
    }
    private void ReadImageAgent()
    {
        dataTexture = DataTexture.Instantiate();
        Texture[] AllImage = Resources.LoadAll<Texture>(DatabaseDirectory.LevelImageAgent);
        foreach (Texture texture in AllImage)
            dataTexture.AddImageAgent(texture);

        if (AllImage.Length < Waves.Length)
        {
            Texture Lock = Resources.Load<Texture>(DatabaseDirectory.LevelLock);
            Debug.Log(Lock);
            for (int i = Waves.Length - AllImage.Length; i > 0; i--)
            {
                
                dataTexture.AddImageAgent(Lock);
            }
        }

    }
    private void ReadOther()
    {
        dataTexture.TextureLock = (Texture)Resources.Load(DatabaseDirectory.LevelLock);
    }
    private void ReadWaves()
    {

        Waves = Resources.LoadAll<TextAsset>(DatabaseDirectory.LevelWaves);
    }
}
